home *** CD-ROM | disk | FTP | other *** search
- /* keys.c - keyboard input and function key translation */
- /* lrs - 2/13/89 */
-
- #include <stdio.h>
- #include <bios.h>
- #include <ctype.h>
- #include "keys.h"
- #include "video.h"
- /*-----------------------------------------------------------------------*/
- int getcmd(void)
- {
- int ch;
-
- ch = bioskey(0);
- if ((ch & 0xFF) !=0) /* not a function key */
- {
- ch &= 0xFF;
- return (toupper(ch));
- }
- else
- return(ch);
- } /* getcmd */
- /*-----------------------------------------------------------------------*/
- unsigned char getkey(char prompt[])
- {
- unsigned char ch;
-
- at(screenrows()-2,0); in(REVERSE);
- cprintf(prompt);
- in(NORMAL); cleareol();
- ch = getcmd();
- at(screenrows()-2,0); cleareol();
- return(ch);
- } /* getkey */
- /*-----------------------------------------------------------------------*/
- void getline(char prompt[], char line[])
- {
- at(screenrows()-2,0); in(REVERSE);
- cprintf(prompt);
- in(NORMAL); cleareol();
- gets(line);
- at(screenrows()-2,0); cleareol();
- } /* getline */
- /*-----------------------------------------------------------------------*/
- void getdec(char prompt[], int* num)
- {
- char tmpstr[20];
-
- getline(prompt, tmpstr);
- if (tmpstr[0] != 0)
- *num = atoi(tmpstr);
- } /* getdec */
- /*-----------------------------------------------------------------------*/
- int atoh(char* tmpstr)
- {
- int done, tmpnum;
- char ch;
- done = tmpnum = 0;
-
- while (!done)
- {
- ch = toupper(*tmpstr++);
- if ((ch >= '0') && (ch <= '9'))
- tmpnum = (tmpnum*0x10) + (ch-'0');
- else if ((ch >= 'A') && (ch <= 'F'))
- tmpnum = (tmpnum*0x10) + (ch-'A'+10);
- else
- done = 1;
- }
- return(tmpnum);
- } /* atoh */
-
- void gethex(char prompt[], int* num)
- {
- char tmpstr[20];
-
- getline(prompt, tmpstr);
- if (tmpstr[0] != 0)
- *num = atoh(tmpstr);
- } /* gethex */
-
- /*---- end of keys.c ----*/
-